﻿using Subkismet.Services.GoogleSafeBrowsing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests.GoogleSafeBrowsing
{


    /// <summary>
    ///This is a test class for CanonicalizationTest and is intended
    ///to contain all CanonicalizationTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CanonicalizationTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetCanonicalizedUrl
        ///</summary>
        [TestMethod()]
        public void GetCanonicalizedUrlTest()
        {
            Canonicalization target = new Canonicalization();

            string url = "http://1.2.nayyeri$.net/1/dfg/./3/dsfds/sdfdsf/../sdfdsf.html#dfgdfg.dgdgdfg";

            string expected = "1.2.nayyeri.net/1/dfg/3/dsfds/sdfdsf.html";
            string actual;

            actual = target.GetCanonicalizedUrl(url);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetHostName
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void GetHostNameTest()
        {
            Canonicalization_Accessor target = new Canonicalization_Accessor();

            string url = "http://1.2.nayyeri$.net/1/2/3.html";

            string expected = "1.2.nayyeri$.net";
            string actual;

            actual = target.GetHostName(url);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetRemainder
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void GetRemainderTest()
        {
            Canonicalization_Accessor target = new Canonicalization_Accessor();

            string url = "http://1.2.nayyeri$.net/1/2/3.html";

            string expected = "/1/2/3.html";
            string actual;

            actual = target.GetRemainder(url);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for RemoveSpecialCharacters
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void RemoveSpecialCharactersTest()
        {
            Canonicalization_Accessor target = new Canonicalization_Accessor();

            string hostname = @"1.2.nayyeri.net";

            string expected = "1.2.nayyeri.net";
            string actual;

            actual = target.RemoveSpecialCharacters(hostname);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ReplaceConsecutiveDots
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void ReplaceConsecutiveDotsTest()
        {
            Canonicalization_Accessor target = new Canonicalization_Accessor();

            string hostname = "1.2...nay.........yeri.ne...t";

            string expected = "1.2.nay.yeri.ne.t";
            string actual;

            actual = target.ReplaceConsecutiveDots(hostname);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for NormalizeIPAddress
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void NormalizeIPAddressTest()
        {
            //Canonicalization_Accessor target = new Canonicalization_Accessor(); // TODO: Initialize to an appropriate value
            //string hostname = string.Empty; // TODO: Initialize to an appropriate value
            //string expected = string.Empty; // TODO: Initialize to an appropriate value
            //string actual;
            //actual = target.NormalizeIPAddress(hostname);
            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for EscapeSpecialChars
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void EscapeSpecialCharsTest()
        {
            Canonicalization_Accessor target = new Canonicalization_Accessor();

            string hostname = "1.2.Nayy&e!ri.net";

            string expected = "1.2.Nayyeri.net";
            string actual;

            actual = target.EscapeSpecialChars(hostname);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ResolveSequences
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void ResolveSequencesTest()
        {
            Canonicalization_Accessor target = new Canonicalization_Accessor();

            string remainder = "/12/35/../gdfg/./sdff5/../gh.html";

            string expected = "/12/gdfg/gh.html";
            string actual;

            actual = target.ResolveSequences(remainder);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for RemoveFragmentIdentifier
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Subkismet.dll")]
        public void RemoveFragmentIdentifierTest()
        {
            Canonicalization_Accessor target = new Canonicalization_Accessor();

            string remainder = "/12/35/gdfg/gh.html#fdgdfgfdg.dfgdfg.dfgfdg";

            string expected = "/12/35/gdfg/gh.html";
            string actual;

            actual = target.RemoveFragmentIdentifier(remainder);

            Assert.AreEqual(expected, actual);
        }
    }
}
